<?php
declare (strict_types = 1);

namespace app\auth\model;

/**
 * @mixin \think\Model
 */
class UserModel extends BaseModel
{
    protected $table = 'tb_users';
    protected $append = ['status_str', 'gender_str', 'last_time_str', 'reg_time_str'];

    //状态
    const STATUS_ACTIVE = 1;
    const STATUS_DIE = 0;
    static $STATUS_STR = [
        self::STATUS_ACTIVE => '激活',
        self::STATUS_DIE => '不能登陆'
    ];
    public function getStatusStrAttr($value,$data)
    {
        return @self::$STATUS_STR[$data['status']];
    }

    //性别
    const GENDER_NUKNOWN = 0;
    const GENDER_MAN = 1;
    const GENDER_WOMAN = 2;
    static $GENDER_STR = [
        self::GENDER_NUKNOWN => '未知',
        self::GENDER_MAN => '男士',
        self::GENDER_WOMAN => '女士',
    ];
    public function getGenderStrAttr($value,$data)
    {
        return @self::$GENDER_STR[$data['gender']];
    }

    public function getRegTimeStrAttr($value,$data)
    {
        return date('Y-m-d H:i:s', $data['reg_time']);
    }
    public function getLastTimeStrAttr($value,$data)
    {
        return date('Y-m-d H:i:s', $data['last_time']);
    }

    /**
     * 密码加密
     * @param string $pwd
     * @return string
     */
    static public function passwordEncode(string $pwd){
        return hash_hmac('md5',md5($pwd),$pwd);
    }


}
